package com.org.gsc.shuaxindemo;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * Created by qundui on 2017/6/23.
 */

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.VH> {
    List<String> Tittles;
    Context mContext;
   IListeners mIListeners;

    public void setIListeners(IListeners IListeners) {
        mIListeners = IListeners;
    }

    public MyAdapter(List<String> tittles, Context context) {
        Tittles = tittles;
        mContext = context;
    }

    @Override
    public MyAdapter.VH onCreateViewHolder(ViewGroup parent, int viewType) {

        View inflate = LayoutInflater.from(mContext).inflate(R.layout.items, parent, false);

        return new VH(inflate);
    }

    @Override
    public void onBindViewHolder(final MyAdapter.VH holder, int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mIListeners!=null){
                    mIListeners.onItemclick(v,holder.getLayoutPosition());
                }
            }
        });
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (mIListeners!=null){
                    mIListeners.OnLongItemClick(v,holder.getLayoutPosition());
                }
                return true;
            }
        });
         holder.mTextView.setText(Tittles.get(position));
    }
    @Override
    public int getItemCount() {
        return Tittles.size();
    }
    public class VH extends RecyclerView.ViewHolder {
        TextView mTextView;
        public VH(View itemView) {
            super(itemView);
            mTextView= (TextView) itemView.findViewById(R.id.tv);
        }
    }
}
